Módulo:ComicsInfobox/Occupation
local occupations = { "actor" = {"Actors"}, "god" = {"Gods"}, "spy" = {"Spies"}, "nurse" = {"Nurses"}, "ninja" = {"Ninjas"}, "pilot" = {"Pilots"}, "boxer" = {"Boxers"}, "thief" = {"Thieves"}, "dancer" = {"Dancers"}, "pirate" = {"Pirates"}, "zombie" = {"Zombies"}, "leader" = {"Leaders"}, "chemist" = {"Chemists"}, "student" = {"Students"}, "teacher" = {"Teachers"}, "assassin" = {"Assassins"}, "reporter" = {"Reporters"}, "criminal" = {"Criminals"}, "inventor" = {"Inventors"}, "engineer" = {"Engineers"}, "crimelord" = {"Crimelords"}, "detective" = {"Detectives"}, "terrorist" = {"Terrorists"}, "conqueror" = {"Conquerors"}, "vigilante" = {"Vigilantes"}, "scientist" = {"Scientists"}, "secretary" = {"Secretaries"}, "mercenary" = {"Mercenaries"}, "politician" = {"Politicians"}, "adventurer" = {"Adventurers"}, guard" = {"Body Guards"}, "bodyguard" = {"Body Guards"}, "retired" = {"Retired Characters"}, minister" = {"Prime Ministers"}, agent" = {"Government Agents"}, operative" = {"Government Agents"}, agent" = {"Intelligence Agents"}, investigator" = {"Private Investigators"}, "magician" = {"Magicians"}, "shaman" = {"Magicians"}, "witch" = {"Magicians"}, "sorcer" = {"Magicians"}, "advocate" = {"Lawyers"}, "lawyer" = {"Lawyers"}, "attorney" = {"Lawyers"}, "ambassador" = {"Ambassadors"}, "diplomat" = {"Ambassadors"}, "dictator" = {"Dictators"}, "doctor" = {"Doctors"}, "surgeon" = {"Doctors"}, "valkyr" = {"Valkyries"}, "empress" = {"Queens (Royalty)"}, "majestrix" = {"Queens (Royalty)"}, "queen" = {"Queens (Royalty)"}, "emperor" = {"Kings (Royalty)"}, "monarch" = {"Kings (Royalty)"}, "majestor" = {"Kings (Royalty)"}, "king" = {"Kings (Royalty)"}, "senator" = {"Senators"}, "janitor" = {"Janitors"}, "praetor" = {"Praetors"}, "cop" = {"Police Officers"}, "police" = {"Police Officers"}, "businesswoman" = {"Business Management"}, } ---------------------------- -- Libraries of functions -- ---------------------------- -- stands for High Frequency local HF = require('Module:ComicsHF') -- Parses invocation parameters, trims whitespace, and removes blanks. local getArgs = require('Dev:Arguments').getArgs -- Gives the name of the current page. It's expensive, so we only do it once. -- The _G then makes it global, available to all page functions. _G.vars = { Pagename = mw.title.getCurrentTitle().text } ---------------------------------------------------------- -- Public functions (called from a Template or article) -- ---------------------------------------------------------- -- There is no standalone template, so no public functions. -------------------------------------------------------- -- Internal functions (used in this and other Modules -- -------------------------------------------------------- function occupations:in_database( name ) if type( self[ string.lower(name) ] ) 'string' then return true else return nil end end function occupations:pluralize( name ) if self:in_database ( string.lower(name) ) then return self[ string.lower(name) ] else -- Brute force method of making a singular plural name = name:gsub( 's$', 'es' ) name = name:gsub( 'x$', 'es' ) name = name:gsub( 'z$', 'es' ) name = name:gsub( 'ch$', 'es' ) name = name:gsub( 'sh$', 'es' ) name = name:gsub( 'y$', 'ies' ) name = name:gsub( 'f$', 'ves' ) name = name:gsub( 'fe$', 'ves' ) name = name:gsub( '^s$', '%1s' ) return name end end function occupations:link( object ) return HF.CategoryLink( self:pluralize(object), vars.Pagename, object ) end function occupations._Occupation( field ) local output = '' local o = {} -- Check for multiple values separated with commas local values = HF.explode( ',', field.Value ) for i, v in ipairs( values ) do v = HF.trim( v ) if valid:in_database( v ) then -- Check if it's a valid value with a plural form. -- If yes - add category links table.insert(o, occupations:link( v ) ) elseif v:match( '%[%.*%%]' ) then if v:match( '|' ) then local target, label = v:match('%[%(.*)%%]') table.insert(o, HF.CategoryLink( self:pluralize(target), vars.Pagename, label )) else local target = v:match('%[%(.*)%%]') table.insert(o, HF.CategoryLink( self:pluralize(target), vars.Pagename, target )) end else -- 3. If no substitution is found -- fallback to a common grammar rules -- and add a page to a Category:Needs valid occupation table.insert( o , occupations:link( v ) .. HF.Category( "Needs valid occupation", vars.Pagename ) ) end end -- If Value2 or ValueRef is provided -- concatenate them to the output if not HF.isempty( field.Value2 ) then output = output .. " " .. field.Value2 end if not HF.isempty( field.ValueRef ) then output = output .. " " .. field.ValueRef end return table.concat(o, ' · ') .. output end ------------------------------------------------- -- Output (send it back to whatever called it) -- ------------------------------------------------- return occupations